package com.venusj.springcloud.service.impl;

import com.venusj.springcloud.dao.PaymentDao;
import com.venusj.springcloud.entity.Payment;
import com.venusj.springcloud.result.CommonResult;
import com.venusj.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author zhangjh
 * @date 2020/3/22
 */
@Service
public class PaymentServiceImpl implements PaymentService {

    @Autowired
    private PaymentDao paymentDao;

    @Value("${server.port}")
    private String serverPort;

    public CommonResult create(Payment payment) {

        int i = paymentDao.create(payment);
        if (i == 0) {
            return new CommonResult(444, "插入失败" + serverPort, null);
        } else {
            return new CommonResult(200, "插入成功" + serverPort, i);
        }
    }

    public CommonResult getPaymentById(Long id) {
        Payment paymentById = paymentDao.getPaymentById(id);
        if (paymentById != null) {

            return new CommonResult(200, "查询成功" + serverPort, paymentById);
        } else {
            return new CommonResult(444, "查询失败，ID:" + id + serverPort, null);
        }
    }
}
